package com.atguigu.flink.chapter05.Transform;

import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.streaming.api.datastream.ConnectedStreams;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.co.CoMapFunction;

/**
 * TODO
 *
 * @author cjp
 * @version 1.0
 * @date 2021/1/20 14:06
 */
public class Flink08_Union {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);

        DataStreamSource<Integer> numDS1 = env.fromElements(1, 2, 3, 4, 5, 6);
        DataStreamSource<Integer> numDS2 = env.fromElements(11, 12, 13, 14, 15, 16);
        DataStreamSource<Integer> numDS3 = env.fromElements(111, 112, 113, 114, 115, 116);


        //TODO union
        DataStream<Integer> unionDS = numDS1.union(numDS2).union(numDS3);

        unionDS
                .map(new MapFunction<Integer, String>() {
                    @Override
                    public String map(Integer value) throws Exception {
                        return value.toString();
                    }
                })
                .print();


        env.execute();
    }

}
/*
    union:
        1、合并多条流（ 大于等于2）
        2、每条流的数据类型一定要一样
 */